package net.skystudio.es.controller;

import com.alibaba.fastjson.JSON;
import net.skystudio.es.common.AbstractController;
import net.skystudio.es.common.BaseResult;
import net.skystudio.es.common.PageBean;
import net.skystudio.es.common.PageResult;
import net.skystudio.es.dto.MixedOrderDTO;
import net.skystudio.es.entity.MixedOrder;
import net.skystudio.es.service.MixedOrderService;
import net.skystudio.es.vo.MixedOrderVO;
import net.skystudio.es.vo.UserQueryPageReqVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

/**
 * 混合订单控制器
 */
@RestController
@RequestMapping("/mixedOrder")
public class MixedOrderController extends AbstractController {

    @Autowired
    private MixedOrderService mixedOrderService;

    /**
     * 分页查询
     *
     * @return
     */
    @PostMapping("/page/{page}/{size}")
    public ResponseResult<Page<MixedOrderVO>> pageAll(@PathVariable("page") Integer page,
                                                      @PathVariable("size") Integer size,
                                                      @RequestBody MixedOrderVO mixedOrderVO) {
        MixedOrderDTO mixedOrderDTO = new MixedOrderDTO();
        BeanUtils.copyProperties(mixedOrderVO, mixedOrderDTO);
        Page<MixedOrder> mixedOrders = mixedOrderService.pageQuery(page, size, mixedOrderDTO);
        Page<MixedOrderVO> result = new PageImpl(mixedOrders.getContent(), mixedOrders.getPageable(),
                mixedOrders.getTotalElements());
        return this.buildResponseResult(result);

    }


}
